package com.cloudm.technician.ui.modules.cloudm_box.change_info

import android.os.Bundle
import android.view.MenuItem
import com.cloudm.technician.R
import com.cloudm.technician.data.model.DeviceInfo
import com.cloudm.technician.extensions.addFragmentToActivity
import com.cloudm.technician.ui.base.BaseActivity

/**
 * 作者: wesley
 * 时间: 2017/12/25
 * 描述: 更换信息界面
 */
class ChangeInfoActivity : BaseActivity() {

    private var info: DeviceInfo? = null
    private var sn: String? = null
    private var fragment: ChangeInfoFragment? = null

    override val optionsMenuEnabled: Boolean
        get() = true

    override val menuRes: Int
        get() = R.menu.menu_device_detail

    override fun handleBundle(bundle: Bundle) {
        info = bundle.getParcelable("info")
        sn = bundle.getString("sn")
    }

    override fun initVariables() {

    }

    override fun initViews(savedInstanceState: Bundle?) {
        headerTitle = R.string.change_info
        displayHomeAsUpEnabled = true

        fragment = manager.findFragmentById(
                R.id.common_content) as? ChangeInfoFragment ?: ChangeInfoFragment.newInstance(info,
                sn)
        addFragmentToActivity(manager, fragment)
    }

    override fun initListener() {

    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        return when (item?.itemId) {
            R.id.menu_next -> {
                fragment?.nestStep()
                true
            }
            else -> false
        }
    }
}